package com.xiemingtian.navdemo.home


import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.Navigation
import com.xiemingtian.navdemo.MainActivity

import com.xiemingtian.navdemo.R
import com.xiemingtian.navdemo.Util
import com.xiemingtian.navdemo.code.CodeNavActivity
import kotlinx.android.synthetic.main.fragment_me.*

class MeFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_me, container, false)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val name = arguments?.getString("name") ?: "unknown"
        nameLabel.text = name

        buttonLogout.setOnClickListener {
            val activity = activity as MainActivity
            activity.setIsLogin(false,"")
            Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_loginFragment,null,Util.launchNavOpt)
        }

        buttonCodeDemo.setOnClickListener {
            val intent = Intent(context,CodeNavActivity::class.java)
            startActivity(intent)
        }
    }
}
